/**
 * Script global
 * @author Sahib J. Leo
 */
jQuery(function($){
  Main.init();
});


/**
 * Clase Main
 * @author Joan Muñoz
 */
var Main = new (function(){
  
  /**
   * Inicializa las acciones
   * @author Joan Muñoz
   */
  this.init = function() {
    
    
    /**
     * Abre el contacto
     */
    $('#contact_btn').fancybox({
      closeBtn: false,
      height: 370,
      minHeight: 370,
      margin: 0,
      padding: 0,
      scrolling: 'no',
      type: 'iframe',
      width: 680,
      minWidth: 680
    });
    
    
    
    /**
     * DropDown Menu
     * @author Joan Muñoz
     */
    $('.dropdown').each(function () {
      $(this).parent().eq(0).hover(function () {
        $('.dropdown:eq(0)', this).show();
      }, function () {
        $('.dropdown:eq(0)', this).hide();
      });
    });
    
    
    /**
     * Slideshow
     * @author Joan Muñoz
     */
    $('#gallery_btn').on('click', function(e){
      e.preventDefault();
      
      var gallery = [
        {image : 'img/galeria/ofj_galeria_01.jpg', title : '', thumb : '', url : ''},
        {image : 'img/galeria/ofj_galeria_02.jpg', title : '', thumb : '', url : ''},
        {image : 'img/galeria/ofj_galeria_03.jpg', title : '', thumb : '', url : ''},
        {image : 'img/galeria/ofj_galeria_04.jpg', title : '', thumb : '', url : ''},
        {image : 'img/galeria/ofj_galeria_05.jpg', title : '', thumb : '', url : ''},
        {image : 'img/galeria/ofj_galeria_06.jpg', title : '', thumb : '', url : ''},
        {image : 'img/galeria/ofj_galeria_07.jpg', title : '', thumb : '', url : ''},
        {image : 'img/galeria/ofj_galeria_08.jpg', title : '', thumb : '', url : ''},
        {image : 'img/galeria/ofj_galeria_09.jpg', title : '', thumb : '', url : ''},
        {image : 'img/galeria/ofj_galeria_10.jpg', title : '', thumb : '', url : ''},
        {image : 'img/galeria/ofj_galeria_11.jpg', title : '', thumb : '', url : ''},
        {image : 'img/galeria/ofj_galeria_12.jpg', title : '', thumb : '', url : ''},
        {image : 'img/galeria/ofj_galeria_13.jpg', title : '', thumb : '', url : ''},
        {image : 'img/galeria/ofj_galeria_14.jpg', title : '', thumb : '', url : ''},
        {image : 'img/galeria/ofj_galeria_15.jpg', title : '', thumb : '', url : ''},
        {image : 'img/galeria/ofj_galeria_16.jpg', title : '', thumb : '', url : ''},
        {image : 'img/galeria/ofj_galeria_17.jpg', title : '', thumb : '', url : ''}
      ];
      
      Main.initGallery( gallery );
      
    });
    
    
    /**
     * Cierra la galería
     * @author Joan Muñoz
     */
    $('#close_gallery').on('click', this.hideGallery);
    
  };
  
  
  /**
   * Inicia la galería
   * @author Joan Muñoz
   */
  this.initGallery = function(gallery) {
    
    
    $("#supersized").html('');
    $.supersized({      
      autoplay : 0,
      slide_interval : 4000,   // Length between transitions
      transition : 3,      // 0-None, 1-Fade, 2-Slide Top, 3-Slide Right, 4-Slide Bottom, 5-Slide Left, 6-Carousel Right, 7-Carousel Left
      transition_speed : 700,    // Speed of transition
      thumbnail_navigation : 0,
      thumb_links : 0,
      start_slide : 1,
      keyboard_nav : 0,                                 
      // Components             
      slide_links : 'blank',  // Individual links for each slide (Options: false, 'num', 'name', 'blank')
      slides : gallery
    });
    
    $("#supersized").css({ 'z-index' : 100001 });
    $('#prevslide, #nextslide, #controls-wrapper').css({
      'display' : 'block',
      'z-index' : 100002
    });
    $('#progress-back').css({ 'z-index' : 100002 });
    
    $('html').css({ 'overflow' : 'hidden' });
  
  };
  
  /**
   * Oculta la galería
   * @author Joan Muñoz
   */
  this.hideGallery = function() {
    
    $("#supersized").html('');
    $("#supersized").css({ 'z-index' : -999 });
    $('#prevslide, #nextslide, #controls-wrapper, #progress-back').css({
      'display' : 'none',
      'z-index' : -999
    });
    
    $('html').css({ 'overflow' : 'auto' });
  };
  
})();























